package com.example.sxmall.service;

import com.whhim.hxh.controller.shopCart.req.OperateCartReq;
import com.whhim.hxh.controller.shopCart.vo.ShopCartVO;
import com.whhim.hxh.redis.RedisService;
import com.whhim.hxh.service.product.CommonProductService;
import com.whhim.hxh.service.shopCart.action.ActionCartService;
import com.whhim.hxh.service.shopCart.dto.OperateCartDTO;
import com.whhim.hxh.service.shopCart.enums.OperateCartEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 购物车
 * @Author whh-yt
 * @Date 2022/3/8 2:46 下午
 */
@Service
public class ShopCartService {

    public final static String SHOPCART_VERSION = "v1";

    @Autowired
    private RedisService redisService;
    @Autowired
    private CommonProductService commonProductService;
    @Autowired
    private ActionCartService actionCartService;

    /**
     * 获取当前用户的购物车信息
     */
    public ShopCartVO queryUserShopCart() {
        return actionCartService.getActionCartMap().get(OperateCartEnum.DEFAULT.getType()).execute(new OperateCartDTO());
    }

    /**
     * 操作购物车
     */
    public ShopCartVO operateShopCart(OperateCartReq operationCartReq) {
        Integer operate = operationCartReq.getOperate();
        OperateCartEnum operateCartEnum = OperateCartEnum.getEnumByType(operate);
        OperateCartDTO operateCartDTO = new OperateCartDTO();
        operateCartDTO.setStoreId(operationCartReq.getStoreId());
        operateCartDTO.setProduct(operationCartReq.getProduct());
        operateCartDTO.setProductList(operationCartReq.getProductList());
        operateCartDTO.setCheckAll(operationCartReq.getCheckAll());
        return actionCartService.getActionCartMap().get(operateCartEnum.getType()).execute(operateCartDTO);
    }
}
